package com.elh.nio.server;

import org.springframework.util.StringUtils;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @author liulei
 **/
public class CreateWebServer {

    public static void main(String[] args) throws IOException {
        ServerSocket serverSocket = new ServerSocket(6666);
        Socket socket = serverSocket.accept();
        InputStream inputStream = socket.getInputStream();
        InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
        BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
        String content = "";
        while (!StringUtils.isEmpty(content = bufferedReader.readLine())) {
            System.out.println(content);
        }
        OutputStream outputStream = socket.getOutputStream();
        outputStream.write("http/1.1 200 ok".getBytes());
        outputStream.flush();
        outputStream.close();
        socket.close();
        serverSocket.close();
    }

}
